package fun.yao.common.monitor.info;

import fun.yao.common.Constant;
import fun.yao.common.msg.HashtableMsg;
import fun.yao.common.uitls.LogUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Hashtable;

public class StartInfo implements IMonitorInfo {

    private long startTime = 0;

    public long getStartTime() {
        return startTime;
    }

    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    public StartInfo()
    {

    }

    public StartInfo(HashtableMsg htm)
    {
        Hashtable<String, String> mapStart = htm.get(0);
        if(mapStart!=null)
        {
            this.startTime = Long.parseLong(mapStart.get("start_time"));
        }
    }

    @Override
    public String toString() {
        return "StartInfo [startTime=" + startTime + "]";
    }

    public void print(StringBuilder sbOut) {
        try
        {

            if(this.startTime!=0)
            {
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                sbOut.append("启动时间："+format.format(new Date(this.startTime))+"\n");
            }

        }catch (Exception e) {
            LogUtil.WriteLog(Constant.BADLY_ERROR, e);
        }
    }

    public HashtableMsg toHashtableMsg() {
        HashtableMsg htm = new HashtableMsg();
        Hashtable<String, String> mapStart = new Hashtable<String, String>();
        mapStart.put("start_time",this.getStartTime()+"");
        htm.add(mapStart);
        return htm;
    }

}
